package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    CustomerDao customerDao;

    @Override
    public void saveOrUpdate(Integer customerId, Customer customer) {
        if(customerId!=null){
            customerDao.update(customer);
        }else {
            customerDao.save(customer);
        }
    }

    @Override
    public void delete(String ids) {
        String[] split = ids.split(",");
        customerDao.delete(split);
    }

    @Override
    public Map<String, Object> findPageByName(Integer page, Integer rows, String customerName) {
        Integer size = (page-1)*rows;
        List<Customer> list=customerDao.findPageByName(size,rows,customerName);
        Map<String,Object> map=new HashMap<>();
        map.put("rows",list);
        Integer total=customerDao.getTotal(customerName);
        map.put("total",total);
        return map;
    }
}
